package com.class05.mapper.impl;

import com.class05.mapper.StudentMapper;
import com.class05.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public class StudentMapperImpl implements StudentMapper {



    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public List<Student> findAll() {
        String sql = "select * from students";
        return jdbcTemplate.query(sql,new
                BeanPropertyRowMapper<>(Student.class));


    }

    @Override
    public Student findById(Integer id) {
        String sql = "select * from students where id=?";
        List<Student> students = jdbcTemplate.
                query(sql, new BeanPropertyRowMapper<>(Student.class), id);
        return students.get(0);

    }
}
